﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace UDFDesign.GUIComponent.CustomControl
{
    public class ToolBoxButton:Button
    {

        private DrawingBoard board;

        public DrawingBoard Board
        {
            get { return board; }
            set
            {
                board = value;
                board.addToolBoxButton(this);
            }
        }
        private ControlTypes type;

        public ControlTypes Type
        {
            get { return type; }
            set { type = value; }
        }

        private Boolean isUsing = false;

        public ToolBoxButton()
        {
        }


        public ToolBoxButton(DrawingBoard board, ControlTypes controlType)
        {
            this.Board = board;
            this.type = controlType;
            //this.BackColor
        }

        protected override void OnClick(EventArgs e)
        {
            if (board != null)
            {
                if (!isUsing)
                {
                    
                    board.releaseDrawingControl();
                    DesignableControl control = ControlFactory.createControl(board, type);
                    board.setDrawingControl(control);
                    this.setUsing(true);
                }
                else
                {
                    board.releaseDrawingControl();
                    this.setUsing(false);
                }
            }
            base.OnClick(e);
        }

        public void setUsing(bool isUsing)
        {
            this.isUsing = isUsing;
            if (isUsing)
            {
                this.BackColor = SystemColors.ControlDark;
            }
            else
            {
                this.BackColor = SystemColors.Control;
            }
        }
    }
}
